package com.shxc.smarttrade;

import android.Manifest;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

import org.xchris.permission.OnPermissionCallback;
import org.xchris.permission.PermissionManager;
import org.xchris.util.DialogUtil;


public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        getPermission();

        setContentView(R.layout.activity_main);

        final GlobalScreenshot screenshot = new GlobalScreenshot(this);
        findViewById(R.id.main_btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                screenshot.takeScreenshot(getWindow().getDecorView(), new Runnable() {
                    @Override
                    public void run() {

                    }
                }, true, true);
            }
        });
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    public void getPermission() {
        PermissionManager.instance().with(this).request(new OnPermissionCallback() {
                                                            @Override
                                                            public void onRequestAllow(String permissionName) {
                                                                Log.e("onRequestAllow", permissionName);
                                                            }


                                                            @Override
                                                            public void onRequestRefuse(String permissionName) {
                                                                Log.e("onRequestRefuse", permissionName);
                                                                DialogUtil.showTips(MainActivity.this, "权限控制",
                                                                        "拒绝" + "\n" + permissionName);
                                                            }

                                                            @Override
                                                            public void onRequestNoAsk(String permissionName) {
                                                                Log.e("onRequestNoAsk", permissionName);
                                                            }
                                                        },
                Manifest.permission.ACCESS_COARSE_LOCATION,
                Manifest.permission.ACCESS_FINE_LOCATION,
                Manifest.permission.CAMERA,
                Manifest.permission.RECORD_AUDIO,
                Manifest.permission.READ_PHONE_STATE,
                Manifest.permission.READ_EXTERNAL_STORAGE,
                Manifest.permission.WRITE_EXTERNAL_STORAGE,
                Manifest.permission.WRITE_SETTINGS,
                Manifest.permission.SYSTEM_ALERT_WINDOW
        );
    }
}
